/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.example.netcracker.model.entity;

import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
import ru.example.netcracker.model.Scheduler;

/**
 *
 * @author Nikolay
 */

@XmlRootElement(name = "tasks")
public class TaskGroup implements Scheduler {
    
    //@XmlElements({
    //    @XmlElement(name = "notification", type = Notification.class)})
    @XmlElementRef
    private final ArrayList<Task> tasks;

    public TaskGroup() {
        tasks = new ArrayList<>();
    }
    
    public TaskGroup(Scheduler tasks) {
        //for (int i = 0; i < tasks.size(); i++) {
        this.tasks = (ArrayList<Task>) tasks.getTasks();
        //}
    }
    
    @Override
    public boolean addTask(Task task) {
        return tasks.add(task);
    }
    
    @Override
    public Task getTask(int index) {
        return tasks.get(index);
    }
    
    @Override
    public List<Task> getTasks() {
        return tasks;
    }
    
    @Override
    public int size() {
        return tasks.size();
    }
    
    @Override
    public boolean removeTask(Task task) {
        return tasks.remove(task);
    }
    
    @Override
    public ArrayList<Task> clone() {
        return (ArrayList<Task>) tasks.clone();
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();        
        for (Task task : tasks) {
            builder.append(task.toString());
        }
        return builder.toString();
    }
}
